package com.service.impl;

import com.bean.Order;
import com.mapper.OrderMapper;
import com.service.OrderService;
import com.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Order getOrderById(Integer orderId) {
        return orderMapper.getOrderById(orderId);
    }

    @Override
    public PageInfo<Order> getOrdersByUserIdWithKeyword(Integer userId, String keyword, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        List<Order> orderList = orderMapper.getOrdersByUserIdWithKeyword(userId, keyword, offset, pageSize);
        int total = orderMapper.countOrdersByUserIdWithKeyword(userId, keyword);
        return new PageInfo<>(pageNum, pageSize, total, orderList);
    }

    @Override
    public boolean insertOrder(Order order) {
        int result = orderMapper.insertOrder(order);
        return result > 0;
    }

    @Override
    public boolean updateOrder(Order order) {
        int result = orderMapper.updateOrder(order);
        return result > 0;
    }

    @Override
    public boolean deleteOrderById(Integer orderId) {
        int result = orderMapper.deleteOrderById(orderId);
        return result > 0;
    }
}